<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>DOM 事件委托模型</title>
    <style>
      table,
      tr,
      td {
        border: 1px solid black;
        text-align: center;
      }
      table {
        border-collapse: collapse;
        width: 400px;
        margin: 50px auto;
      }
    </style>
  </head>
  <body>
    <table id="table">
      <tr>
        <th>学号</th>
        <th>姓名</th>
      </tr>
      <tr>
        <td>001</td>
        <td>张三</td>
      </tr>
      <tr>
        <td>002</td>
        <td>李四</td>
      </tr>
    </table>
    <script>
      const table = document.getElementById("table");
      table.addEventListener("click", (event) => {
        console.log(event.target.closest("td")?.textContent);
      });
    </script>
  </body>
</html>
